package com.atguigu.demo.meta.controller;

import com.atguigu.demo.meta.bean.TableMetaInfo;
import com.atguigu.demo.meta.service.TableMetaInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 元数据表 前端控制器
 * </p>
 *
 * @author zhangchen
 * @since 2024-11-19
 */
@RestController
@RequestMapping("/meta/tableMetaInfo")
public class TableMetaInfoController {

    @Autowired
    TableMetaInfoService tableMetaInfoService;

    @GetMapping("/metainfo/{id}")
    public TableMetaInfo getMetaInfo(@PathVariable("id") Long id) {

        return tableMetaInfoService.getById(id);
    }

    @GetMapping("/metainfo")   //?tablename=xxx
    public List<TableMetaInfo> getMetaInfo(@RequestParam("tablename") String tableName) {
        List<TableMetaInfo> tableList = tableMetaInfoService.list(new QueryWrapper<TableMetaInfo>().eq("table_name", tableName));
        return tableList;
    }

    @PostMapping("/metainfo")
    public String saveMetaInfo(@RequestBody TableMetaInfo tableMetaInfo) {

        tableMetaInfoService.saveOrUpdate(tableMetaInfo);
        return  "success";
    }
}
